<template>
  <div class="c-eqpt-model-view-doc-add">
    <el-button type="primary" @click="visible = true">
      {{ multLang('btn_upload_a') }}
    </el-button>
    <c-dialog
      custom-class="c-eqpt-model-view-doc-add-dialog"
      :visible.sync="visible"
      width="500px"
      :title="multLang('title_d')"
    >
      <el-form
        :model="form"
        :rules="rules"
        ref="form"
        label-width="100px"
        :validate-on-rule-change="false"
      >
        <el-form-item :label="multLang('title_file_a', ':')" prop="file_id">
          <c-upload-input
            v-model="form.file_id"
            :placeholder="tplLang('text_choose_a', ['title_file_a'])"
          ></c-upload-input>
        </el-form-item>
        <el-form-item :label="multLang('title_file_b', ':')" prop="file_type">
          <c-select
            v-model="form.file_type"
            :options="fileCategoryList"
            :placeholder="tplLang('text_choose_a', ['title_file_b'])"
          ></c-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="close">
          {{ multLang('title_aak_l') }}
        </el-button>
        <el-button type="primary" @click="submit">
          {{ multLang('btn_sure_a') }}
        </el-button>
      </template>
    </c-dialog>
  </div>
</template>
<script>
import { addAssetModelDoc } from '@/http/api/v1/eqpt-model'
export default {
  name: 'CEqptListViewDocAdd',
  components: {},
  props: {
    data: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      visible: false,
      form: {
        file_id: '',
        file_type: ''
      }
    }
  },
  computed: {
    fileCategoryList() {
      return this.optionList('file_category')
    },
    fileCategoryMap() {
      return this.optionMap('file_category')
    },
    rules() {
      return {
        file_id: {
          required: true,
          message: this.tplLang('msg_a', ['title_file_a']),
          trigger: 'change'
        },
        file_type: {
          required: true,
          message: this.tplLang('msg_a', ['title_file_b']),
          trigger: 'change'
        }
      }
    }
  },
  watch: {},
  beforeCreate() {},
  created() {
    this.setOption({ key: 'file_category' })
  },
  beforeMount() {},
  mounted() {},
  beforeUpdate() {},
  updated() {},
  activated() {},
  deactivated() {},
  beforeDestroy() {},
  destroyed() {},
  methods: {
    reset() {
      this.$refs.form.resetFields()
    },
    close() {
      this.reset()
      this.visible = false
    },
    submit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          addAssetModelDoc({ id: this.data.id, ...this.form }).then(
            ({ code }) => {
              if (code === 200) {
                this.close()

                this.$emit('close')
              }
            }
          )
        }
      })
    }
  }
}
</script>
<style lang="scss">
.c-eqpt-model-view-doc-add-dialog {
  height: 250px;
}
</style>
